﻿using System;
using BL.Abstract;
using BL.Generic;
using DAL.Abstract;
using DAL.Repositories;

namespace BL.Class
{
    public class SecurityBL : ISecurityBL
    {
        private readonly ISecurityHelper securityHelperBl;        

        public SecurityBL()
        {
            securityHelperBl = new SecurityHelper();
        }

        public SecurityBL(ISecurityHelper securityHelperBl)
        {
            this.securityHelperBl = securityHelperBl;
        }

        public GenericResult<bool> CheckIfUserIsAdmin(string userLogin)
        {
            try
            {
                if (securityHelperBl.CheckIfUserIsAdmin(userLogin))
                {
                    return new GenericResult<bool>
                    {
                        SingleObjectAnswer = true,
                        BlAnswer = Answer.Success
                    };
                }
                return new GenericResult<bool>
                {
                    SingleObjectAnswer = true,
                    BlAnswer = Answer.Success
                };
            }
            catch (Exception ex)
            {
                return new GenericResult<bool>
                {
                    Exception = ex.Message,
                    SingleObjectAnswer = false                    
                };
            }
        }
    }
}
